import request from '@/utils/request'
import type{ QueryParams, RuleForm } from "@/views/order/management/types";
// 查询所有订单
export function listAllOrder() {
  return request({
    url: '/order/listAll',
    method: 'get'
  })
}

// 查询订单列表
export function listOrder(query: QueryParams) {
  return request({
    url: '/order',
    method: 'get',
    params: query
  })
}

// 分页查询订单列表
export function listOrderByPage(query: QueryParams) {
  return request({
    url: '/order/page',
    method: 'get',
    params: query
  })
}

// 根据id查询订单
export function getOrderById(orderId: string) {
  return request({
    url: '/order/' + orderId,
    method: 'get'
  })
}

// 根据状态查询订单
export function getOrderByStatus(status: string) {
  return request({
    url: '/order/getByStatus/' + status,
    method: 'get'
  })
}

//根据桌台id查询订单
export function getOrderByTable(tableId: string) {
  return request({
    url: '/order/getByTable/' + tableId,
    method: 'get',
  })
}

// 新增订单
export function addOrder(data: RuleForm) {
  return request({
    url: '/order',
    method: 'post',
    data: data
  })
}

// 修改订单
export function updateOrder(data: RuleForm) {
  return request({
    url: '/order',
    method: 'put',
    data: data
  })
}

// 删除订单
export function deleteOrder(orderId: string) {
  return request({
    url: '/order/' + orderId,
    method: 'delete'
  })
}

// 批量删除订单
export function deleteOrderBatch(orderIds: string[]) {
  return request({
    url: '/order/delBatch/' + orderIds,
    method: 'delete'
  })
}

// 开台点餐
export function makeNewOrder(params: {
  tableId: string,
  people: number
}) {
  return request({
    url: '/order/makeNewOrder',
    method: 'post',
    data: {
      table: { tableId: params.tableId },
      peopleCount: params.people,
      orderStatus: '待支付'
    }
  })
}

// 录入点餐菜品明细，也可以发起post请求
export function enterItem(params: any) {
  return request({
    url: '/order/enterItem',
    method: 'get',
    params: params
  })
}
// 结束录入菜品
export function endOrder() {
  return request({
    url: '/order/endOrder',
    method: 'get'
  })
}

// 确认支付，也可以发起post请求
export function makePayment(params: any) {
  return request({
    url: '/order/makePayment',
    method: 'post',
    params: params
  })
}

// 修改一行菜品明细数量
export function changeQuantity(params:any) {
  return request({
    url: '/order/changeQuantity',
    method: 'get',
    params: params
  })
}

// 删除一行菜品明细
export function deleteItem(dishId:number) {
  return request({
    url: '/order/deleteItem/'+dishId,
    method: 'get'
  })
}